<template>
	<view>
		<nav-bar :bgColor="['#4A67D6','#4A67D6']" fontColor="#FFFFFF" title="出库">
			<!-- <view slot="right" class="search_box"></view> -->
		</nav-bar>
		<!-- 公共组件-每个页面必须引入 -->
		<public-module></public-module>
		<!-- <mescroll-body ref="mescrollRef" @init="mescrollInit" :down="downOption" @down="downCallback" style="margin-top: 20rpx;"
		 @up="upCallback" :up="upOption"> -->
		<view class="orderNumber">案件编号：{{orderNo}}</view>
		<view class="orderNumber">物品数：{{dataList.length}}</view>
		<view class="orderNumber">扫到数量：{{rfId.length}}</view>
		<view v-if="index == 0" v-for="(item,index1) in dataList">
			<uni-list>
				<uni-list-item 
					thumb="/static/icon/event_icon/task_stock.png" :title="'物品名：'+item.itemName + ' | ' + '特征：' + item.itemName" :note="'创建日期：'+item.createTime"
					link="reLaunch" clickable :disabled="item.warehouseInYn == null ? false : true">
				</uni-list-item>
			</uni-list>
		</view>
		<view style="height: 150rpx;">
			<view style="position: fixed;bottom: 10rpx;width: 100%;">
				<button @click="submit" type="primary" style="width: 90%;margin: 0 auto;">提交出库</button>
			</view>
		</view>
	</view>
</template>

<script>
	var main = null;
	var receiver = null;
	import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js';
	import uniList from '@/components/uni-list/uni-list.vue';
	export default {
		mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
		components: {
			uniList,
		},
		data() {
			return {
				// btnnum: 0, //topbar
				array: ['领取', '借用', '处理'],
				index: 0,
				orderNo: 'A310331430918839',
				orderNumber: "10",
				//搜索内容
				downOption: {
					native: false,
					use: true, // 是否启用下拉刷新; 默认true
					auto: true
				},
				upOption: {
					use: true, // 是否启用上拉加载; 默认true
					auto: false,
					noMoreSize: 5, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看
				},
				dataList: [],
				userInfo: {},
				id:'',
				repeatRfid: [],
				rfId: []
			};
		},
		onLoad(e) {
			this.id = e.id
			this.getDataList();
			this.get_gb();
		},
		onShow() {

		},
		//方法
		methods: {
			// bindPickerChange: function(e) {
			// 	console.log('picker发送选择改变，携带值为', e.target.value)
			// 	this.index = e.target.value
			// },
			submit(){
				
				let opt = {
					url: 'web/tbWmsMaterialDeliveryLine/outbound',
					method: 'POST'
				};
				let params = {
					 rfidCodes : this.rfId
				};
				console.log(params)
				this.$http.httpTokenRequest(opt,params).then(res => {
					console.log(res)
					if(res.data.code == 200){
						this.getDataList();
					}
				})
			},
			get_gb() {
				var that = this;
				main = plus.android.runtimeMainActivity();
				receiver = plus.android.implements('io.dcloud.android.content.BroadcastReceiver', {
					onReceive: function(context, intent) {
						plus.android.importClass(intent);
						var data = intent.getExtra("data");
						if (data) {
							that.repeatRfid.push(data)
							for(let i=0;i<that.repeatRfid.length;i++){
								if(that.rfId.indexOf(that.repeatRfid[i]) == -1){
									that.rfId.push(that.repeatRfid[i])
									console.log(that.rfId)
								}
							}
						}
					}
				});
				var IntentFilter = plus.android.importClass('android.content.IntentFilter');
				let filter = new IntentFilter();
				filter.addAction('android.rfid.epccode');
				var info = main.registerReceiver(receiver, filter)
				// main.unregisterReceiver(receiver)
			},
			getDataList(){
				let opt = {
					url:'oms/tbRelateItemTakeLog/'+this.id,
					method:'GET'
				};
				this.$http.httpTokenRequest(opt).then(res =>{
					this.dataList = res.data.data.items
					this.orderNo = res.data.data.caseNo
				})
			},
			onPageJump(url) {
				uni.navigateTo({
					url: url
				});
			},

			/*下拉刷新的回调 */
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				//联网加载数据
				this.loadData(page.num);
			},
			loadData(pageNo) {
				let opts = {
					url: 'mesg/yunheFireOrEventMesg/search/' + pageNo + '/' + 10,
					method: 'POST'
				};
				let params = {
					eventType: '林业巡检',
					// contactId: uni.getStorageSync('userInfo').data.sysUser.id,
					// status: 'COMPLETED'
				};
				this.$http.httpTokenRequest(opts, params).then(res => {
						if (res.data.code == 200) {
							this.mescroll.endSuccess(res.data.data.records.length)
							if (pageNo == 1) {
								this.dataList = res.data.data.records;
							} else {
								this.dataList = this.dataList.concat(res.data.data.records);
							}
							this.orderNumber = res.data.data.total
							console.log(this.dataList)
							uni.hideLoading();
						} else if (res.data.code == 401) {
							uni.hideLoading();
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								position: 'center'
							});
							setTimeout(() => {
								uni.navigateTo({
									url: './homePage'
								})
							}, 1500)
						} else {
							uni.hideLoading();
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								position: 'center'
							});
						}
					})
					.catch(res => {
						this.mescroll.endErr();
						uni.hideLoading();
					});
			}
		},
		//页面下来刷新
		onPullDownRefresh() {
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 2000);
		},
		//页面上拉触底
		onReachBottom() {
			console.log('上拉');
		},
		//用户点击分享
		onShareAppMessage(e) {
			return this.wxShare();
		}
	};
</script>
<style lang="scss" scoped>
	@import '@/style/mixin.scss';

	page {
		background: #FFFFFF;
	}

	.end-title {
		display: flex;
		border-bottom: 1px solid #E5E5E5;
	}

	.end-title view {
		flex-grow: 1;
		text-align: center;
		background: #FFFFFF;
		// border-top: 1px solid #E5E5E5;
	}

	.btna {

		border-bottom: 2px solid #007AFF;
		color: #007AFF;
	}

	.tab {
		padding: 30rpx;
		font-size: 35rpx;
	}

	.mapStyle {
		height: 1200rpx;
		width: 100%;
		margin-top: 10rpx;
	}

	/*说明*/
	.orderNumber {
		margin: 20rpx 0rpx 30rpx 30rpx;
		font-size: 35rpx;
		font-weight: bold;
		// font-family: '宋体';
		// font-weight: ;
	}

	.notice {
		font-size: 30upx;
		padding: 40upx 0;
		border-bottom: 1upx solid #eee;
		text-align: center;
	}

	/*展示上拉加载的数据列表*/
	.news_list {
		padding: 30rpx;
		background-color: #fff;
		margin-bottom: 20rpx;

		.title {
			font-size: 28rpx;
			color: #333;
			font-weight: bold;
			@include bov(2);
		}

		.content {
			margin-top: 10rpx;
			font-size: 24rpx;
			color: #999;
			@include bov(3);
		}

		.content_state {
			margin-top: 10rpx;
			display: flex;
			justify-content: space-between;

			text {
				font-size: 24rpx;
				color: #666;
			}
		}
	}

	.search_box {
		width: 45upx;
		height: 45upx;
		background-image: url("./rfid.png");
		background-position: center center;
		background-repeat: no-repeat;
		background-size: 100% 100%;
		margin-right: 25upx;
	}



	.search_home_box {
		width: 90%;
		height: 64rpx;
		background-color: #FFFFFF;
		border-radius: 20rpx;
		margin: 0 auto;
		display: flex;

		// margin-top: 100rpx;
		.prompt {
			font-size: 28rpx;
			color: #393939;
			margin-left: 25rpx;
			margin-top: 16rpx;
		}

		.icon_search {
			background-image: url('/pages/home/map_ic_search.png');
			background-position: center;
			background-repeat: no-repeat;
			background-size: cover;
			width: 30rpx;
			height: 30rpx;
			margin-left: 25rpx;
			margin-top: 16rpx;
		}
	}


	.table_title {
		border: 1rpx solid #ececec;
		height: 50rpx;
		line-height: 50rpx;
		float: left;
		width: 42.5%;
		text-align: center;
	}

	.table_title_clean {
		height: 50rpx;
		line-height: 50rpx;
		float: right;
		width: 15%;
		text-align: center;
	}

	.table_box {
		background-color: rgba($color: $themeColor, $alpha: 1);

		.table_title {
			padding: 0rpx 20rpx;
			font-size: 22rpx;
			height: 60rpx;
			line-height: 60rpx;
			color: #ffffff;
			text-align: center;
			font-weight: bold;
			background-color: rgba($color: $themeColor, $alpha: 1);
		}

		.table_head {
			display: flex;
			align-content: center;
			background-color: rgba($color: $themeColor, $alpha: 0.35);

			text {
				padding: 15rpx 20rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				flex: 1;
				flex-shrink: 0;
				font-size: 28rpx;
				color: #333;
				font-weight: bold;
				border-right: 2rpx solid rgba($color: $themeColor, $alpha: 0.2);

				&:last-child {
					border-right: 0;
					flex: 2;
				}
			}
		}

		.table_content {
			display: flex;
			align-content: center;
			border-top: 2rpx solid rgba($color: $themeColor, $alpha: 0.2);
			background-color: #f5ffc6;

			text {
				padding: 15rpx 20rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				flex: 1;
				font-size: 22rpx;
				color: #999;
				border-right: 2rpx solid rgba($color: $themeColor, $alpha: 0.3);

				&:last-child {
					border-right: 0;
					flex: 2;
				}
			}
		}
	}
</style>
